<?php
namespace Common\Model;
use Think\Model;

class CategoryModel extends Model{
	

	public $_validate = array();

	protected $trueTableName = 'info_category';

	public function addCategory(){
		if($_POST['category'] == ''){
			$this->error='栏目名称不能为空';
			return false;
		}
		$category = $this->add($_POST);
		if($category){
			return true;
		}else{
			$this->error="栏目添加失败";
			return false;
		}
	}

	public function getCategoryList(){

		$cateList = $this->select();
		$cate = new \Org\Util\Data;
		$cateList = $cate::tree($cateList,'category','id','pid');
		return $cateList;
	}

	public function editCategory(){
		$id = I('get.id');
		if($_POST['category'] == ''){
			$this->error='栏目名称不能为空';
			return false;
		}
		$category = $this->where("id ='{$id}'")->save($_POST);
		if($category){
			return true;
		}else{
			$this->error="栏目更新失败";
			return false;
		}
	}

	public function findById($id){
		return $this->where(array('id'=>$id))->find();
	}

}
